package ar.edu.utn.frsf.cidisi.ginet.generation.pnml2wscdl.elementstemplate;

import org.eclipse.emf.common.util.EList;
import org.pnml.tools.epnk.pnmlcoremodel.Page;
import org.w3._2005._10.cdl.CdlFactory;
import org.w3._2005._10.cdl.TChoreography;
import org.w3._2005._10.cdl.TException;
import org.w3._2005._10.cdl.TWorkunit;

public class CancelWSCDL extends WSCDLStructure {
	
	public CancelWSCDL(Page page, TChoreography choreography){
		this.page = page;
		this.choreography = choreography;
	}
	
	public TWorkunit createWSCDLElement(){
		
		TException exception = CdlFactory.eINSTANCE.createTException();
		
		exception.setName("cancel");
	
		EList<Page> pages1 = this.getPages(page);
		TWorkunit tWorkunit = CdlFactory.eINSTANCE.createTWorkunit();
		
		tWorkunit.setName("cancel");
		
		if(pages1.size() > 0){			
			this.addTo(tWorkunit, this.createPackageWscdl(pages1.get(0), this.choreography));
			exception.getWorkunit().add(tWorkunit);
		}
		
		for(int i = 1; i < pages1.size(); i++){

			TWorkunit tWorkunit1 = CdlFactory.eINSTANCE.createTWorkunit();
			
			tWorkunit1.setName("cancel" + i);
			
			this.addTo(tWorkunit1, this.createPackageWscdl(pages1.get(i), this.choreography));
			exception.getWorkunit().add(tWorkunit1);
			
		}
		
		this.choreography.setExceptionBlock(exception);
		
		return tWorkunit;
		
	}

}
